package com.example.framework.mqtt.core.properties;

import org.springframework.boot.context.properties.NestedConfigurationProperty;

import java.io.Serializable;

/**
 * <p>
 * mqtt 基本参
 * </p>
 *
 * @author sfjiang
 * @since 2024/11/26 17:39
 */
public class MqttConfigProperties implements Serializable {

    /**
     * 用户名
     */
    private String username;

    /**
     * 密码
     */
    private String password;

    /**
     * 服务器ip
     */
    private String serverIp;

    /**
     * 服务器端口
     */
    private int serverPort;

    /**
     * 客户端Id(不可重复)
     */
    private String clientId;


    /**
     * 全局订阅的 topic，可被全局监听到，保留 session 停机重启，依然可以接受到消息。
     */
    private String globalSubscribeTopic;

    /**
     * 设置连接超时值,该值以秒为单位 0 禁用超时处理,这意味着客户端将等待，直到网络连接成功或失败
     */
    private Integer connectionTimeout;

    /**
     * 是否自动重连
     */
    private boolean reconnect = true;

    private long reconnectInterval = 5000L;

    /**
     * 客户端是否应该在连接时重置会话状态。如果设置为 true，客户端将不会恢复之前的会话状态，而是开始一个新的会话。如果设置为 false，客户端将尝试恢复之前的会话状态
     */
    private boolean cleanSession = true;

    /**
     * 心跳时间
     */
    private int keepAliveInterval = 60;

    /**
     * 读取缓冲区的大小，以字节为单位。当从服务器读取数据时，MQTT 客户端将使用此大小作为缓冲区。
     */
    private int readBufferSize = 8192;

    /**
     * 客户端愿意接收的最大 MQTT 数据包大小
     */
    private int maxByteInMessage = 10485760;


    /**
     * 会话过期间隔时间（以秒为单位），如果设置为 null，则使用默认值（通常是无限期）
     */
    private Integer sessionExpiryInterval = null;

    /**
     * 遗嘱消息
     */
    @NestedConfigurationProperty
    private WillMessage willMessage;

    @NestedConfigurationProperty
    private SSLProperties ssl;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getServerIp() {
        return serverIp;
    }

    public void setServerIp(String serverIp) {
        this.serverIp = serverIp;
    }

    public int getServerPort() {
        return serverPort;
    }

    public void setServerPort(int serverPort) {
        this.serverPort = serverPort;
    }

    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public String getGlobalSubscribeTopic() {
        return globalSubscribeTopic;
    }

    public void setGlobalSubscribeTopic(String globalSubscribeTopic) {
        this.globalSubscribeTopic = globalSubscribeTopic;
    }

    public Integer getConnectionTimeout() {
        return connectionTimeout;
    }

    public void setConnectionTimeout(Integer connectionTimeout) {
        this.connectionTimeout = connectionTimeout;
    }

    public boolean isReconnect() {
        return reconnect;
    }

    public void setReconnect(boolean reconnect) {
        this.reconnect = reconnect;
    }

    public long getReconnectInterval() {
        return reconnectInterval;
    }

    public void setReconnectInterval(long reconnectInterval) {
        this.reconnectInterval = reconnectInterval;
    }

    public boolean isCleanSession() {
        return cleanSession;
    }

    public void setCleanSession(boolean cleanSession) {
        this.cleanSession = cleanSession;
    }

    public int getKeepAliveInterval() {
        return keepAliveInterval;
    }

    public void setKeepAliveInterval(int keepAliveInterval) {
        this.keepAliveInterval = keepAliveInterval;
    }

    public int getReadBufferSize() {
        return readBufferSize;
    }

    public void setReadBufferSize(int readBufferSize) {
        this.readBufferSize = readBufferSize;
    }

    public int getMaxByteInMessage() {
        return maxByteInMessage;
    }

    public void setMaxByteInMessage(int maxByteInMessage) {
        this.maxByteInMessage = maxByteInMessage;
    }

    public Integer getSessionExpiryInterval() {
        return sessionExpiryInterval;
    }

    public void setSessionExpiryInterval(Integer sessionExpiryInterval) {
        this.sessionExpiryInterval = sessionExpiryInterval;
    }

    public WillMessage getWillMessage() {
        return willMessage;
    }

    public void setWillMessage(WillMessage willMessage) {
        this.willMessage = willMessage;
    }

    public SSLProperties getSsl() {
        return ssl;
    }

    public void setSsl(SSLProperties ssl) {
        this.ssl = ssl;
    }
}
